<?php
include_once ("koneksi.php");

class ModelNews {

	public function __construct (){
			$this-> koneksi = new Koneksi();
		} //<!--end of __construct--> 
	  
	public function getNews (){
		$this->koneksi->_connect();
		$query = "select * from berita";
		
		$result = mysql_query($query);
		while ($data = mysql_fetch_array($result)) {
			$array[$data['ID_BERITA']]=new News($data['ID_BERITA'], $data['ID_USER'], $data['JUDULBERITA'], $data['ISIBERITA']);
		}
		$this->koneksi->_close();
		if (!empty($array))
		{
			return $array;
		}
	}
	
	public function addNews($id_user, $judulberita, $isiberita)
	{
		$this->koneksi->_connect();
		$query = mysql_query
		("INSERT INTO `berita` (id_berita, id_user, judulberita, isiberita) 
		VALUES ('', '$id_user', '$judulberita', '$isiberita');");
		$this->koneksi->_close();
		return true;
	}
	
	public function  updateNews($id_berita, $id_user, $judulberita, $isiberita){
		$this->koneksi->_connect();
		$query = mysql_query("UPDATE berita SET  id_user ='$id_user', judulberita='$judulberita', isiberita='$isiberita' WHERE id_berita = '$id_berita' ;");
		$this->koneksi->_close();
		return true;
	}//<!--end of updateMember-->
	
	public function  deleteNews($id_berita){
		$this->koneksi->_connect();
		$query = mysql_query("DELETE FROM `berita` WHERE ID_BERITA = '$id_berita';");	
		$this->koneksi->_close();
		return true;
	}
	
}
?>
	

	
<?php
	
class News {
	public $id_berita;
	public $id_user;
	public $judulberita;
	public $isiberita;
	
	public function __construct($id_berita, $id_user, $judulberita, $isiberita)  
    {  
        $this->id_berita = $id_berita;
	    $this->id_user = $id_user;
		$this->judulberita = $judulberita;
		$this->isiberita = $isiberita;
    } 
}
?>